﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EIS_desktop
{
    public partial class PayCalendar : Form
    {
        public PayCalendar()
        {
            InitializeComponent();
        }

        /// <summary>
        /// List of all employees
        /// </summary>
        /// <returns></returns>
        private DataTable GetEmployeeList()
        {
          string datestr = "1-" + comboBox1.Text  + "-" + comboBox2.Text;
           //string datestr = "1-" + monYear1.Month + "-" + monYear1.Year;
            System.Data.SqlClient.SqlConnection sqlcon = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.AppSettings["constr"]);
            System.Data.SqlClient.SqlCommand sqlcmd = new System.Data.SqlClient.SqlCommand("SELECT EMPLOYEE.Empid, EMPLOYEE.FirstName as [First Name], EMPLOYEE.Lastname as [Last Name], " +
                " PAYROLL.BalanceWithHeldAmount as [Balance With Held Amount] FROM EMPLOYEE LEFT OUTER JOIN PAYROLL ON EMPLOYEE.EMPID = PAYROLL.EMPID AND PAYROLL.PAYPERIOD = dateadd(m,-1,'" + datestr + "')", sqlcon);
            System.Data.SqlClient.SqlDataAdapter sqladp = new System.Data.SqlClient.SqlDataAdapter(sqlcmd);
            
            DataTable dt = new DataTable();
            sqladp.Fill(dt);
            return dt;
        }

       
        private void PayCalendar_Load(object sender, EventArgs e)
        {
            for (int year = 2000; year <= 2030; year++)
            {
                comboBox2.Items.Add(year);
            }
            dataGridView1.Hide();
            //dataGridView1.DataSource = GetEmployeeList();
            //DataGridViewButtonColumn dgvbuttoncol = new DataGridViewButtonColumn();
            //dgvbuttoncol.Text = "View/Edit PayRoll";
            //dgvbuttoncol.UseColumnTextForButtonValue = true;
            //dataGridView1.Columns.Add(dgvbuttoncol);

        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataGridView1.DataSource = GetEmployeeList();
            dataGridView1.Columns[0].Visible = false;
            dataGridView1.Show();
        }

     

        private void viewEditToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewRow dgrow = dataGridView1.CurrentRow;
            if (dgrow == null)
            {
                MessageBox.Show("Select or right click a row");

            }
            else
            {
             PayRoll2 objpr = new PayRoll2((int)dataGridView1.Rows[dgrow.Index].Cells[0].Value,comboBox1.Text + "-" +Convert.ToInt32(comboBox2.Text),
                                 dataGridView1.Rows[dgrow.Index].Cells[1].Value.ToString());
                
            //   objpr.MdiParent = this.MdiParent;
                objpr.Show();
            }
        }

        private void monYear1_MonYearSelected(object sender, EventArgs e)
        {
            MessageBox.Show("U CLICKED RIGHT");
        }

       
     

       

       

    }
}
